package com.google.android.exoplayer2.mediacodec;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.media.MediaCodecInfo;
import android.media.MediaCodecInfo.CodecCapabilities;
import android.media.MediaCodecInfo.CodecProfileLevel;
import android.media.MediaCodecList;
import android.text.TextUtils;
import android.util.Pair;
import android.util.SparseIntArray;
import androidx.annotation.Nullable;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import o.ahe;
import o.amz;
import o.anb;
import o.anr;

@SuppressLint({"InlinedApi"})
@TargetApi(16)
public final class MediaCodecUtil {
    private static final SparseIntArray ʽ = new SparseIntArray();
    private static final Pattern ˊ = Pattern.compile("^\\D?(\\d+)$");
    private static final HashMap<d, List<ahe>> ˋ = new HashMap();
    private static final Map<String, Integer> ˎ = new HashMap();
    private static final SparseIntArray ˏ = new SparseIntArray();
    private static final SparseIntArray ॱ = new SparseIntArray();
    private static int ॱॱ = -1;

    public static class DecoderQueryException extends Exception {
        private DecoderQueryException(Throwable th) {
            super("Failed to query underlying media codecs", th);
        }
    }

    interface b {
        int ˎ();

        boolean ˏ();

        boolean ˏ(String str, CodecCapabilities codecCapabilities);

        MediaCodecInfo ॱ(int i);
    }

    static final class a implements b {
        private a() {
        }

        public int ˎ() {
            return MediaCodecList.getCodecCount();
        }

        public MediaCodecInfo ॱ(int i) {
            return MediaCodecList.getCodecInfoAt(i);
        }

        public boolean ˏ() {
            return false;
        }

        public boolean ˏ(String str, CodecCapabilities codecCapabilities) {
            return "video/avc".equals(str);
        }
    }

    @TargetApi(21)
    static final class c implements b {
        private final int ˋ;
        private MediaCodecInfo[] ˎ;

        public c(boolean z) {
            this.ˋ = z ? 1 : 0;
        }

        public int ˎ() {
            ॱ();
            return this.ˎ.length;
        }

        public MediaCodecInfo ॱ(int i) {
            ॱ();
            return this.ˎ[i];
        }

        public boolean ˏ() {
            return true;
        }

        public boolean ˏ(String str, CodecCapabilities codecCapabilities) {
            return codecCapabilities.isFeatureSupported("secure-playback");
        }

        private void ॱ() {
            if (this.ˎ == null) {
                this.ˎ = new MediaCodecList(this.ˋ).getCodecInfos();
            }
        }
    }

    static final class d {
        public final String ˊ;
        public final boolean ˏ;

        public d(String str, boolean z) {
            this.ˊ = str;
            this.ˏ = z;
        }

        public int hashCode() {
            return (this.ˏ ? 1231 : 1237) + (((this.ˊ == null ? 0 : this.ˊ.hashCode()) + 31) * 31);
        }

        public boolean equals(@Nullable Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null || obj.getClass() != d.class) {
                return false;
            }
            d dVar = (d) obj;
            if (TextUtils.equals(this.ˊ, dVar.ˊ) && this.ˏ == dVar.ˏ) {
                return true;
            }
            return false;
        }
    }

    static final class e implements Comparator<ahe> {
        private e() {
        }

        public /* synthetic */ int compare(Object obj, Object obj2) {
            return ˏ((ahe) obj, (ahe) obj2);
        }

        public int ˏ(ahe o_ahe, ahe o_ahe2) {
            return ॱ(o_ahe) - ॱ(o_ahe2);
        }

        private static int ॱ(ahe o_ahe) {
            return o_ahe.ˎ.startsWith("OMX.google") ? -1 : 0;
        }
    }

    static final class f implements Comparator<ahe> {
        private f() {
        }

        public /* synthetic */ int compare(Object obj, Object obj2) {
            return ˏ((ahe) obj, (ahe) obj2);
        }

        public int ˏ(ahe o_ahe, ahe o_ahe2) {
            return ˏ(o_ahe) - ˏ(o_ahe2);
        }

        private static int ˏ(ahe o_ahe) {
            String str = o_ahe.ˎ;
            if (str.startsWith("OMX.google") || str.startsWith("c2.android")) {
                return -1;
            }
            if (anr.ˋ >= 26 || !str.equals("OMX.MTK.AUDIO.DECODER.RAW")) {
                return 0;
            }
            return 1;
        }
    }

    static {
        ˏ.put(66, 1);
        ˏ.put(77, 2);
        ˏ.put(88, 4);
        ˏ.put(100, 8);
        ˏ.put(110, 16);
        ˏ.put(122, 32);
        ˏ.put(244, 64);
        ॱ.put(10, 1);
        ॱ.put(11, 4);
        ॱ.put(12, 8);
        ॱ.put(13, 16);
        ॱ.put(20, 32);
        ॱ.put(21, 64);
        ॱ.put(22, DnsConfig.MAX_CACHE_ENTRIES);
        ॱ.put(30, 256);
        ॱ.put(31, WXMediaMessage.TITLE_LENGTH_LIMIT);
        ॱ.put(32, WXMediaMessage.DESCRIPTION_LENGTH_LIMIT);
        ॱ.put(40, 2048);
        ॱ.put(41, 4096);
        ॱ.put(42, 8192);
        ॱ.put(50, 16384);
        ॱ.put(51, 32768);
        ॱ.put(52, WXMediaMessage.THUMB_LENGTH_LIMIT);
        ˎ.put("L30", Integer.valueOf(1));
        ˎ.put("L60", Integer.valueOf(4));
        ˎ.put("L63", Integer.valueOf(16));
        ˎ.put("L90", Integer.valueOf(64));
        ˎ.put("L93", Integer.valueOf(256));
        ˎ.put("L120", Integer.valueOf(WXMediaMessage.DESCRIPTION_LENGTH_LIMIT));
        ˎ.put("L123", Integer.valueOf(4096));
        ˎ.put("L150", Integer.valueOf(16384));
        ˎ.put("L153", Integer.valueOf(WXMediaMessage.THUMB_LENGTH_LIMIT));
        ˎ.put("L156", Integer.valueOf(262144));
        ˎ.put("L180", Integer.valueOf(1048576));
        ˎ.put("L183", Integer.valueOf(4194304));
        ˎ.put("L186", Integer.valueOf(16777216));
        ˎ.put("H30", Integer.valueOf(2));
        ˎ.put("H60", Integer.valueOf(8));
        ˎ.put("H63", Integer.valueOf(32));
        ˎ.put("H90", Integer.valueOf(DnsConfig.MAX_CACHE_ENTRIES));
        ˎ.put("H93", Integer.valueOf(WXMediaMessage.TITLE_LENGTH_LIMIT));
        ˎ.put("H120", Integer.valueOf(2048));
        ˎ.put("H123", Integer.valueOf(8192));
        ˎ.put("H150", Integer.valueOf(32768));
        ˎ.put("H153", Integer.valueOf(WXMediaMessage.MINI_PROGRAM__THUMB_LENGHT));
        ˎ.put("H156", Integer.valueOf(524288));
        ˎ.put("H180", Integer.valueOf(2097152));
        ˎ.put("H183", Integer.valueOf(8388608));
        ˎ.put("H186", Integer.valueOf(33554432));
        ʽ.put(1, 1);
        ʽ.put(2, 2);
        ʽ.put(3, 3);
        ʽ.put(4, 4);
        ʽ.put(5, 5);
        ʽ.put(6, 6);
        ʽ.put(17, 17);
        ʽ.put(20, 20);
        ʽ.put(23, 23);
        ʽ.put(29, 29);
        ʽ.put(39, 39);
        ʽ.put(42, 42);
    }

    @Nullable
    public static ahe ˎ() throws DecoderQueryException {
        ahe ॱ = ॱ("audio/raw", false);
        return ॱ == null ? null : ahe.ˏ(ॱ.ˎ);
    }

    @Nullable
    public static ahe ॱ(String str, boolean z) throws DecoderQueryException {
        List ˏ = ˏ(str, z);
        return ˏ.isEmpty() ? null : (ahe) ˏ.get(0);
    }

    public static synchronized List<ahe> ˏ(String str, boolean z) throws DecoderQueryException {
        List<ahe> list;
        synchronized (MediaCodecUtil.class) {
            d dVar = new d(str, z);
            list = (List) ˋ.get(dVar);
            if (list == null) {
                b cVar = anr.ˋ >= 21 ? new c(z) : new a();
                List ˊ = ˊ(dVar, cVar, str);
                if (z && ˊ.isEmpty() && 21 <= anr.ˋ && anr.ˋ <= 23) {
                    b aVar = new a();
                    ArrayList ˊ2 = ˊ(dVar, aVar, str);
                    if (!ˊ2.isEmpty()) {
                        amz.ˏ("MediaCodecUtil", "MediaCodecList API didn't list secure decoder for: " + str + ". Assuming: " + ((ahe) ˊ2.get(0)).ˎ);
                    }
                    ˊ = ˊ2;
                    cVar = aVar;
                }
                if ("audio/eac3-joc".equals(str)) {
                    ˊ.addAll(ˊ(new d("audio/eac3", dVar.ˏ), cVar, str));
                }
                ˏ(str, ˊ);
                list = Collections.unmodifiableList(ˊ);
                ˋ.put(dVar, list);
            }
        }
        return list;
    }

    public static int ˏ() throws DecoderQueryException {
        int i = 0;
        if (ॱॱ == -1) {
            ahe ॱ = ॱ("video/avc", false);
            if (ॱ != null) {
                CodecProfileLevel[] ˎ = ॱ.ˎ();
                int length = ˎ.length;
                int i2 = 0;
                while (i < length) {
                    i2 = Math.max(ॱ(ˎ[i].level), i2);
                    i++;
                }
                i = Math.max(i2, anr.ˋ >= 21 ? 345600 : 172800);
            }
            ॱॱ = i;
        }
        return ॱॱ;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    @androidx.annotation.Nullable
    public static android.util.Pair<java.lang.Integer, java.lang.Integer> ˋ(java.lang.String r6) {
        /*
        r0 = 0;
        r1 = 0;
        if (r6 != 0) goto L_0x0005;
    L_0x0004:
        return r0;
    L_0x0005:
        r2 = "\\.";
        r3 = r6.split(r2);
        r4 = r3[r1];
        r2 = -1;
        r5 = r4.hashCode();
        switch(r5) {
            case 3006243: goto L_0x0032;
            case 3006244: goto L_0x003c;
            case 3199032: goto L_0x001f;
            case 3214780: goto L_0x0028;
            case 3356560: goto L_0x0046;
            default: goto L_0x0015;
        };
    L_0x0015:
        r1 = r2;
    L_0x0016:
        switch(r1) {
            case 0: goto L_0x001a;
            case 1: goto L_0x001a;
            case 2: goto L_0x0050;
            case 3: goto L_0x0050;
            case 4: goto L_0x0055;
            default: goto L_0x0019;
        };
    L_0x0019:
        goto L_0x0004;
    L_0x001a:
        r0 = ˎ(r6, r3);
        goto L_0x0004;
    L_0x001f:
        r5 = "hev1";
        r4 = r4.equals(r5);
        if (r4 == 0) goto L_0x0015;
    L_0x0027:
        goto L_0x0016;
    L_0x0028:
        r1 = "hvc1";
        r1 = r4.equals(r1);
        if (r1 == 0) goto L_0x0015;
    L_0x0030:
        r1 = 1;
        goto L_0x0016;
    L_0x0032:
        r1 = "avc1";
        r1 = r4.equals(r1);
        if (r1 == 0) goto L_0x0015;
    L_0x003a:
        r1 = 2;
        goto L_0x0016;
    L_0x003c:
        r1 = "avc2";
        r1 = r4.equals(r1);
        if (r1 == 0) goto L_0x0015;
    L_0x0044:
        r1 = 3;
        goto L_0x0016;
    L_0x0046:
        r1 = "mp4a";
        r1 = r4.equals(r1);
        if (r1 == 0) goto L_0x0015;
    L_0x004e:
        r1 = 4;
        goto L_0x0016;
    L_0x0050:
        r0 = ˏ(r6, r3);
        goto L_0x0004;
    L_0x0055:
        r0 = ॱ(r6, r3);
        goto L_0x0004;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.exoplayer2.mediacodec.MediaCodecUtil.ˋ(java.lang.String):android.util.Pair<java.lang.Integer, java.lang.Integer>");
    }

    private static ArrayList<ahe> ˊ(d dVar, b bVar, String str) throws DecoderQueryException {
        String name;
        try {
            ArrayList<ahe> arrayList = new ArrayList();
            String str2 = dVar.ˊ;
            int ˎ = bVar.ˎ();
            boolean ˏ = bVar.ˏ();
            loop0:
            for (int i = 0; i < ˎ; i++) {
                MediaCodecInfo ॱ = bVar.ॱ(i);
                name = ॱ.getName();
                if (ˏ(ॱ, name, ˏ, str)) {
                    for (String str3 : ॱ.getSupportedTypes()) {
                        if (str3.equalsIgnoreCase(str2)) {
                            CodecCapabilities capabilitiesForType = ॱ.getCapabilitiesForType(str3);
                            boolean ˏ2 = bVar.ˏ(str2, capabilitiesForType);
                            boolean ˏ3 = ˏ(name);
                            if ((!ˏ || dVar.ˏ != ˏ2) && (ˏ || dVar.ˏ)) {
                                if (!ˏ && ˏ2) {
                                    arrayList.add(ahe.ॱ(name + ".secure", str2, capabilitiesForType, ˏ3, true));
                                    break loop0;
                                }
                            }
                            arrayList.add(ahe.ॱ(name, str2, capabilitiesForType, ˏ3, false));
                        }
                    }
                    continue;
                }
            }
            return arrayList;
        } catch (Exception e) {
            if (anr.ˋ > 23 || arrayList.isEmpty()) {
                amz.ˋ("MediaCodecUtil", "Failed to query codec " + name + " (" + str3 + ")");
                throw e;
            }
            amz.ˋ("MediaCodecUtil", "Skipping codec " + name + " (failed to query capabilities)");
        } catch (Throwable e2) {
            throw new DecoderQueryException(e2);
        }
    }

    private static boolean ˏ(MediaCodecInfo mediaCodecInfo, String str, boolean z, String str2) {
        if (mediaCodecInfo.isEncoder()) {
            return false;
        }
        if (!z && str.endsWith(".secure")) {
            return false;
        }
        if (anr.ˋ < 21 && ("CIPAACDecoder".equals(str) || "CIPMP3Decoder".equals(str) || "CIPVorbisDecoder".equals(str) || "CIPAMRNBDecoder".equals(str) || "AACDecoder".equals(str) || "MP3Decoder".equals(str))) {
            return false;
        }
        if (anr.ˋ < 18 && "OMX.MTK.AUDIO.DECODER.AAC".equals(str)) {
            if ("a70".equals(anr.ˎ)) {
                return false;
            }
            if ("Xiaomi".equals(anr.ˏ) && anr.ˎ.startsWith("HM")) {
                return false;
            }
        }
        if (anr.ˋ == 16 && "OMX.qcom.audio.decoder.mp3".equals(str) && ("dlxu".equals(anr.ˎ) || "protou".equals(anr.ˎ) || "ville".equals(anr.ˎ) || "villeplus".equals(anr.ˎ) || "villec2".equals(anr.ˎ) || anr.ˎ.startsWith("gee") || "C6602".equals(anr.ˎ) || "C6603".equals(anr.ˎ) || "C6606".equals(anr.ˎ) || "C6616".equals(anr.ˎ) || "L36h".equals(anr.ˎ) || "SO-02E".equals(anr.ˎ))) {
            return false;
        }
        if (anr.ˋ == 16 && "OMX.qcom.audio.decoder.aac".equals(str) && ("C1504".equals(anr.ˎ) || "C1505".equals(anr.ˎ) || "C1604".equals(anr.ˎ) || "C1605".equals(anr.ˎ))) {
            return false;
        }
        if (anr.ˋ < 24 && (("OMX.SEC.aac.dec".equals(str) || "OMX.Exynos.AAC.Decoder".equals(str)) && "samsung".equals(anr.ˏ) && (anr.ˎ.startsWith("zeroflte") || anr.ˎ.startsWith("zerolte") || anr.ˎ.startsWith("zenlte") || "SC-05G".equals(anr.ˎ) || "marinelteatt".equals(anr.ˎ) || "404SC".equals(anr.ˎ) || "SC-04G".equals(anr.ˎ) || "SCV31".equals(anr.ˎ)))) {
            return false;
        }
        if (anr.ˋ <= 19 && "OMX.SEC.vp8.dec".equals(str) && "samsung".equals(anr.ˏ) && (anr.ˎ.startsWith("d2") || anr.ˎ.startsWith("serrano") || anr.ˎ.startsWith("jflte") || anr.ˎ.startsWith("santos") || anr.ˎ.startsWith("t0"))) {
            return false;
        }
        if (anr.ˋ <= 19 && anr.ˎ.startsWith("jflte") && "OMX.qcom.video.decoder.vp8".equals(str)) {
            return false;
        }
        if ("audio/eac3-joc".equals(str2) && "OMX.MTK.AUDIO.DECODER.DSPAC3".equals(str)) {
            return false;
        }
        return true;
    }

    private static void ˏ(String str, List<ahe> list) {
        if ("audio/raw".equals(str)) {
            Collections.sort(list, new f());
        } else if (anr.ˋ < 21 && list.size() > 1) {
            String str2 = ((ahe) list.get(0)).ˎ;
            if ("OMX.SEC.mp3.dec".equals(str2) || "OMX.SEC.MP3.Decoder".equals(str2) || "OMX.brcm.audio.mp3.decoder".equals(str2)) {
                Collections.sort(list, new e());
            }
        }
    }

    private static boolean ˏ(String str) {
        return anr.ˋ <= 22 && (("ODROID-XU3".equals(anr.ˊ) || "Nexus 10".equals(anr.ˊ)) && ("OMX.Exynos.AVC.Decoder".equals(str) || "OMX.Exynos.AVC.Decoder.secure".equals(str)));
    }

    private static Pair<Integer, Integer> ˎ(String str, String[] strArr) {
        if (strArr.length < 4) {
            amz.ˏ("MediaCodecUtil", "Ignoring malformed HEVC codec string: " + str);
            return null;
        }
        Matcher matcher = ˊ.matcher(strArr[1]);
        if (matcher.matches()) {
            int i;
            String group = matcher.group(1);
            if ("1".equals(group)) {
                i = 1;
            } else if ("2".equals(group)) {
                i = 2;
            } else {
                amz.ˏ("MediaCodecUtil", "Unknown HEVC profile string: " + group);
                return null;
            }
            Integer num = (Integer) ˎ.get(strArr[3]);
            if (num != null) {
                return new Pair(Integer.valueOf(i), num);
            }
            amz.ˏ("MediaCodecUtil", "Unknown HEVC level string: " + matcher.group(1));
            return null;
        }
        amz.ˏ("MediaCodecUtil", "Ignoring malformed HEVC codec string: " + str);
        return null;
    }

    private static Pair<Integer, Integer> ˏ(String str, String[] strArr) {
        if (strArr.length < 2) {
            amz.ˏ("MediaCodecUtil", "Ignoring malformed AVC codec string: " + str);
            return null;
        }
        try {
            Integer valueOf;
            Integer valueOf2;
            if (strArr[1].length() == 6) {
                valueOf = Integer.valueOf(Integer.parseInt(strArr[1].substring(0, 2), 16));
                valueOf2 = Integer.valueOf(Integer.parseInt(strArr[1].substring(4), 16));
            } else if (strArr.length >= 3) {
                valueOf = Integer.valueOf(Integer.parseInt(strArr[1]));
                valueOf2 = Integer.valueOf(Integer.parseInt(strArr[2]));
            } else {
                amz.ˏ("MediaCodecUtil", "Ignoring malformed AVC codec string: " + str);
                return null;
            }
            int i = ˏ.get(valueOf.intValue(), -1);
            if (i == -1) {
                amz.ˏ("MediaCodecUtil", "Unknown AVC profile: " + valueOf);
                return null;
            }
            int i2 = ॱ.get(valueOf2.intValue(), -1);
            if (i2 != -1) {
                return new Pair(Integer.valueOf(i), Integer.valueOf(i2));
            }
            amz.ˏ("MediaCodecUtil", "Unknown AVC level: " + valueOf2);
            return null;
        } catch (NumberFormatException e) {
            amz.ˏ("MediaCodecUtil", "Ignoring malformed AVC codec string: " + str);
            return null;
        }
    }

    private static int ॱ(int i) {
        switch (i) {
            case 1:
            case 2:
                return 25344;
            case 8:
            case 16:
            case 32:
                return 101376;
            case 64:
                return 202752;
            case DnsConfig.MAX_CACHE_ENTRIES /*128*/:
            case 256:
                return 414720;
            case WXMediaMessage.TITLE_LENGTH_LIMIT /*512*/:
                return 921600;
            case WXMediaMessage.DESCRIPTION_LENGTH_LIMIT /*1024*/:
                return 1310720;
            case 2048:
            case 4096:
                return 2097152;
            case 8192:
                return 2228224;
            case 16384:
                return 5652480;
            case 32768:
            case WXMediaMessage.THUMB_LENGTH_LIMIT /*65536*/:
                return 9437184;
            default:
                return -1;
        }
    }

    @Nullable
    private static Pair<Integer, Integer> ॱ(String str, String[] strArr) {
        if (strArr.length != 3) {
            amz.ˏ("MediaCodecUtil", "Ignoring malformed MP4A codec string: " + str);
            return null;
        }
        try {
            if (!"audio/mp4a-latm".equals(anb.ॱ(Integer.parseInt(strArr[1], 16)))) {
                return null;
            }
            int i = ʽ.get(Integer.parseInt(strArr[2]), -1);
            if (i != -1) {
                return new Pair(Integer.valueOf(i), Integer.valueOf(0));
            }
            return null;
        } catch (NumberFormatException e) {
            amz.ˏ("MediaCodecUtil", "Ignoring malformed MP4A codec string: " + str);
            return null;
        }
    }
}
